# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Eivind Uggedal <eu@eju.no>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=go-bootstrap
_realname="${pkgname%-*}"
pkgver=1.4.3
pkgrel=3
pkgdesc="Go programming language compiler used for bootstraping"
url="http://www.golang.org/"
arch="armel armhf armv7 x86 x86_64"
license="BSD"
depends=""
depends_dev=""
makedepends="bash"
options="!strip"
install=""
subpackages=""
source="
	https://storage.googleapis.com/golang/${_realname}${pkgver}.src.tar.gz
	no-pic.patch
	no-longjmp-redefine.patch
	fix-arm-hackery.patch
	default-sc-getpw-r-size-max.patch
	new-binutils.patch
	"
builddir="$srcdir"/$_realname

# NOTE: building go-bootstrap for x86 with grsec kernel requires:
#           sysctl -w kernel.modify_ldt=1

build() {
	cd "$builddir/src"

	export GOPATH="$srcdir"
	export GOROOT="$builddir"
	export GOBIN="$GOROOT"/bin
	export GOROOT_FINAL=/usr/lib/$pkgname

	export CGO_ENABLED=0

	case "$CARCH" in
	armel)    export GOARCH="arm" GOARM="5" ;;
	armhf)    export GOARCH="arm" GOARM="6" ;;
	armv7)    export GOARCH="arm" GOARM="7" ;;
	x86)      export GOARCH="386" GO386="387" ;;
	x86_64)   export GOARCH="amd64" ;;
	*)        return 1 ;;
	esac

	./make.bash --no-clean || return 1
}

package() {
	cd "$builddir"
	mkdir -p "$pkgdir"/usr/lib/$pkgname "$pkgdir"/usr/lib/$pkgname

	# The source needs to be installed due to an upstream
	# bug (https://github.com/golang/go/issues/2775).
	cp -a bin pkg src "$pkgdir"/usr/lib/$pkgname || return 1

	# Remove tests and bashscripts from /usr/lib/go/src.
	# Those shouldn't be affacted by the upstream bug (see above).
	find "$pkgdir"/usr/lib/$pkgname/src \( -type f -a -name "*_test.go" \) \
		-exec rm -rf \{\} \+ || return 1
	find "$pkgdir"/usr/lib/$pkgname/src \( -type d -a -name "testdata" \) \
		-exec rm -rf \{\} \+ || return 1
	find "$pkgdir"/usr/lib/$pkgname/src \( -type f -a -name "*.bash" \) \
		-exec rm -rf \{\} \+ || return 1
}

sha512sums="12bade4bce9aa4b34e2b9495ae65a1fc6a2449b3a43bc4de85c8b87ba223c2f999b2f37c1e2fe1188d8521118b5e5357d27afb8b85c0b8ebb4503d4125d25273  go1.4.3.src.tar.gz
a8e95c3c536a30e15b9bad5e623a085c521739639a58ac638679d99413a1bee8823729783123cbe4495ac42822df31f4776f0380a63786b9f4fc73190e012ae5  no-pic.patch
3a9b665f8fda89729c4c269ea82f82ee515f0026d26f1d51e2cf84054456e394afc14875e7ed29280a12488907d50c70af313e2e4a5b62c328bbade098db9d4d  no-longjmp-redefine.patch
573146b72c980af5e41540fd7912b5579b050e41ac9d808e8d14268cf0a0fa1a70e6fade85011c0f18f1a428bc95b225d8b8345be1c50656dc69046ef1eb0b40  fix-arm-hackery.patch
5de9747fe60bbc60aa8ac9870f397fa8750723f919fea25a6afc22066be45a8ad193f7935d3deacbe85c032be89b8ace0a7e82b6c9981ddaf3b7f6e8d140c61f  default-sc-getpw-r-size-max.patch
9c25d58d8172ade339d468b86b51a2ad964bf1a2e80d917934f318a78b9e5820f261d4742afec467ef567a905039184829c449ee9ac8f08385029d130badaebf  new-binutils.patch"
